package moyangjia.retailers.uims.api;

import moyangjia.retailers.common.domain.R;
import moyangjia.retailers.storage.common.domain.R;
import moyangjia.retailers.storage.sys.domain.SysGroup;
import moyangjia.retailers.storage.sys.domain.dto.GroupDto;
import moyangjia.retailers.storage.sys.service.IGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * @description:
 * @author: honglei
 * @time: 2021/3/15 0015 14:10
 */
@RestController
@RequestMapping("/api/uims/menu/")
public class GroupController {
    @Autowired
    IGroupService groupService;


    @PostMapping("add")
    public R addDict(SysGroup group) {
        return R.ok(groupService.save(group));
    }

    @PostMapping("remove/{id}")
    public Object remove(@PathVariable(value = "id") String id) {
        return R.ok(groupService.removeById(id));
    }

    @PostMapping("removeList")
    public Object removeList(List<String> ids) {
        return R.ok(groupService.removeByIds(ids));
    }

    @PostMapping("update")
    public R update(GroupDto group) {
        if (null==group||null==group.getId()){
            return R.error(40001,"id不存在");
        }
        return R.ok(groupService.updateExtend(group));
    }




    @GetMapping("get/{id}")
    public R get(@PathVariable(value = "id") String id) {
        SysGroup group=groupService.getById(id);
        if (group==null){
            return R.error(40001,"id不存在");
        }
        return R.ok(group);
    }

    @GetMapping("getDetail/{id}")
    public R getDetail(@PathVariable(value = "id") String id) {
        return R.ok(groupService.getDetail(id));
    }

    @GetMapping("getList")
    public R getList(SysGroup group) {
        return R.ok(groupService.getList(group));
    }



    @PostMapping("romeveUserGroup")
    public R  romeveUserGroup(Serializable id ){
        return R.ok(groupService.romeveUserGroup(id));
    }



}
